package czt.ocr.controller;

import czt.ocr.service.OcrService;
import lombok.AllArgsConstructor;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RequestMapping("/ocr")
@RestController
@AllArgsConstructor
public class OcrController {
    private final OcrService ocrService;

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String recognizeImage(@RequestParam("file") MultipartFile file) throws TesseractException, IOException {

        // 调用OcrService中的方法进行文字识别
        return ocrService.recognizeText(file);
    }

    @PostMapping("/parseFile")
    public String parseFile(@RequestParam("file") MultipartFile file) throws Exception {
        return ocrService.parseFile(file);
    }
}
